import speech_recognition as sr

def control():
    recognizer = sr.Recognizer()
    with sr.Microphone() as source:
        recognizer.adjust_for_ambient_noise(source, duration=1)
        print("Say something please !")
        audio = recognizer.listen(source, phrase_time_limit=2)
        try:
            print("end")
            text = recognizer.recognize_google(audio, language='zh-CN')  # 还可以选择不同的数据源，从而用来识别不同的语言
            print("You said : {}".format(text))

            sentence = str(text)

            comlist = ['上', '下', '左', '右']
            senlist = []
            for i in sentence:
                senlist.append(i)
            for command in senlist:
                if command in comlist:
                    print(command)
                    return command
        except:
            print("Sorry I can't hear you!")




